A compiler accomplishes a translation of a source code listing to a set of object files that are written in machine language. During the compilation action, code generation and optimization decisions are made, and the resultant coded output is then subjected to a linking action which primarily relocates code and data, resolves branch addresses and provides binding to run-time libraries.
Many modern programming languages support the concept of separate compilation, wherein a source code listing is broken up into separate modules that can be fed individually to a language translator for generation of the machine code. The use of source code modules during a compilation process enables substantial savings in required memory in the computer on which the compiler executes. In a co-pending application entitled "Compiler with Intermodular Procedure Optimization" (Attorney Docket 10961037-1) Ser. No. 08/795,986 filed Feb. 5, 1997, and assigned to the same Assignee as this Application, a method is described for improving the optimization of a source code listing which is compiled in a modular fashion. That method involves the derivation of a number of program-wide tables which enable inter-modular referencing to occur, even though individual modules are, in the main, processed individually during compilation. A principal use of the invention in the aforesaid patent application is to enable insertion of in-line code listings in place of direct call sites in the individual modules being optimized. A direct call is one wherein a routine is specifically noted in the routine by a name which enables a direct reference to the called routine, wherever it is stored.
Such code listings also include indirect calls. An indirect call is a reference to a subroutine (i.e., the callee) wherein the subroutine is not identified until program run time. Indirect calls are present in many of today's programming languages (e.g., C, Fortran, etc.) and also play a significant role in object-oriented programming languages like C++ and Java. Indirect calls, by their very nature require considerable processing and procedure delay time for their execution. If it were possible to identify, in advance, the callee of an indirect call, the code comprising the callee routine could be inserted into the caller's routine by in-lining or a direct call could be inserted to the identified code (a direct call requiring less processing than an indirect call).
As above indicated, in-lining replaces a call site in the caller routine with the callee routine's code. In-line substitution eliminates call overhead and tailors the call to the particular set of arguments passed at a given caller site. Nevertheless, since in the prior art the identification of a callee subject to an indirect call has not been known until run time, such indirect calls have remained in the compiled code and have resulted in increases in processing time.
In "Reducing Indirect Function Call Overhead in C++ Programs" Calder et al., ACM Principles of Programming Languages, Portland, Oreg., 1994, a technique is described for replacing an indirect call with a matching test, followed by a direct call. However it is assumed that prior to optimization, a profiling phase identifies a list of callee candidates for each indirect call site by observing program behavior on a test input. Such indirect call information is expensive to accumulate.
In other prior art, a compiler has been described which performs a series of passes over a database that contains information about all of the procedures in an application. A variety of analyses are performed to provide information as to which procedures are invoked by a direct call; which names refer to a same location (alias analysis); which pointers point to which locations (pointer tracking); which procedures use which scalars (scalar analysis); and which procedures should be in-lined at which call sites (in-line analysis); etc. The results of the analyses are then employed during the compile action to achieve application improvement. See "Engineering and Inter-Procedural Optimizing Compiler", Loeliger et al., Convex Computer Corporation, Richardson, Tex. (undated).
While the Loeliger et al. procedure performs many analyses, there is no indication of an attempt to identify, in advance, callee procedures that are subject to an indirect call.
Accordingly, it is an object of this invention to provide an improved compiler which attempts to identify a callee that is the subject of indirect call.
It is another object of this invention to provide an improved compiler which both identifies prospective callees of indirect calls and either in-lines the code of the identified callees into caller routine listings or inserts a direct call thereto.